using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Text.RegularExpressions;
using HQLAddin.Highlighting.Classificators.BaseClass;
using HQLAddin.Highlighting.Formatters;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace HQLAddin.Highlighting.Classificators
{
	[Export(typeof (IClassifierProvider))]
	[ContentType("xml")]
	internal sealed class StringClassifierProvider : IClassifierProvider
	{
		[Import] private IClassificationTypeRegistryService classificationRegistry;

		#region IClassifierProvider Members

		public IClassifier GetClassifier(ITextBuffer textBuffer)
		{
			return textBuffer
				.Properties
				.GetOrCreateSingletonProperty(() => new StringClassifier(classificationRegistry));
		}

		#endregion
	}

	internal class StringClassifier : RegexBasedClassifier
	{
		public StringClassifier(IClassificationTypeRegistryService classificationRegistry)
			: base(classificationRegistry)
		{
		}

		public override string FormatterName
		{
			get { return StringFormat.Name; }
		}

		public override IEnumerable<Regex> Regexs
		{
			get { yield return new Regex(@"(\'[^\'\\]*(?:\\.[^\'\\]*)*\'*)"); }
		}
	}
}